import os.path

from PyQt4 import QtGui

import fogmini

from fogmini import global_objects
from fogmini.api.fogbugz import FogBugzAPIError
from fogmini.dialogs import LoginDetails
from fogmini.tray_menu import TrayMenu

base_path = os.path.dirname(fogmini.__file__)

class SystemTrayIcon(QtGui.QSystemTrayIcon):
    def __init__(self, parent):
        QtGui.QSystemTrayIcon.__init__(self, QtGui.QIcon(QtGui.QPixmap(os.path.join(base_path, "logo.gif"))), parent)

        self.menu = TrayMenu()
        self.setContextMenu(self.menu)

        self.activated.connect(self.activated_slot)

        global_objects.app.login_successful.connect(self.login_successful)

        self.show()

    def activated_slot(self, activation_reason):
        if activation_reason == 3:
            # Left click
            ld = LoginDetails()
            ld.exec_()
        #elif activation_reason == 1:
        #    self.menu.populate()

    def login_successful(self):
        self.showMessage("Login Successful", "You have been successfully authenticated with FogBugz.", 5000)
